
package com.bangcommunity.bbframe.sdm.aop.handler;

import com.bangcommunity.bbframe.common.exception.ValidateUtil;
import com.bangcommunity.bbframe.sdm.annotation.DataSourceKey;
import com.bangcommunity.bbframe.sdm.aop.WrapAspectUtil;
import com.bangcommunity.bbframe.sdm.datasource.MultDataSourceKey;
import org.aspectj.lang.ProceedingJoinPoint;

import java.lang.reflect.Method;

/**
 * Created by tanghc on 17/1/18.
 */
public class DataSourceSwichPreHandler extends PreHandler {
    @Override
    protected boolean doPreHandler(ProceedingJoinPoint pjp, Object[] args, Method method, String className) {
        DataSourceKey annotation = WrapAspectUtil.findAnnotation(pjp.getTarget().getClass(), method, DataSourceKey.class);
        if (null != annotation) {
            ValidateUtil.checkNotEmpty(annotation.value(),"必须设置数据源标识");
            MultDataSourceKey.setDataSourceKey(annotation.value());
        }
        return true;
    }
}
